//
//  ZAQVisitorTableViewController.swift
//  ZAQWBDZT
//
//  Created by 赵安庆 on 16/9/20.
//  Copyright © 2016年 zaq. All rights reserved.
//

import UIKit

class ZAQVisitorTableViewController: UITableViewController ,loginDelegate{
    //是否登录的标示

//    var isLogin:Bool = false
    var isLogin: Bool = ZAQUserAccountViewModel.sharedUserAccountViewModel.isLogin

    var visitorView :ZAQVisitorView?



    override func loadView() {
        if isLogin {
            super.loadView()
        }else{
             visitorView = ZAQVisitorView()

            // 设置代理为当前控制器
            visitorView?.delegate = self
            view = visitorView

            setupNavUI()

            visitorView?.loginClosure = { [weak self] in

                print("我是访客视图闭包调用过来的")
                self?.requestLoginOperation()

            }
        }

    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func setupNavUI(){

        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录",target: self,action: #selector(loginAction))
             navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册",target: self,action: #selector(loginAction))

    }
   @objc private func loginAction(){
    print("你点击了登录操作")
    requestLoginOperation()
    }

// MARK:代理方法
    func didSelectedButton() {
        print("我是代理调用过来的注册按钮点击事件")
    }

    private func requestLoginOperation(){

        let OAuthVc = ZAQOAuthViewController()
        let nav = ZAQNavigationViewController(rootViewController: OAuthVc)
        present(nav, animated: true, completion: nil)

    }
}
